﻿function Helper() {

    this.GetOrderAll = function (func) {
        AysPost("GetOrderAll",
              { UserName: userName },
            func);
    };

    this.GetOrderDetails = function (OrderId, func) {
        AysPost("GetOrderAll",
              { orderId: OrderId },
            func);
    };

    this.GetAllRoles = function (func) {
        AysPost("getAllRole",
              { },
            func);
    };

    this.GetAllUsers = function (func) {
        AysPost("getAllUser",
              {  },
            func);
    };

    this.Login = function (UserName, Password, func) {
        AysPost("login",
              {
                  username: UserName,
                  password: Password
              },
            func);
    };

    this.SaveDocument = function (Documents,DocumentDetails, func) {
        AysPost("UpdateDocument",
              {
                  documents: Documents,
                  documentDetails : DocumentDetails
              },
            func);
    };

    this.GetATP = function (ProdIds, func) {
        AysPost("GetATP",
              {
                  prodIds: ProdIds
              },
            func);
    };

    this.UpdateQueueStatus = function (QueueId, QueueStatus, func) {
        AysPost("UpdateQueueStatus",
              {
                  queueId: QueueId,
                  queueStatus: QueueStatus
              },
            func);
    };

    this.ApproveOrder = function (Documents, DocumentDetails, func) {
        AysPost("ApproveOrder",
              {
                  documents: Documents,
                  documentDetails: DocumentDetails
              },
            func);
    };

    this.GetTransectionByOrderNoAndMat = function (OrderNo, MatNo, func) {
        AysPost("GetTransectionByOrderNoAndMat",
              {
                  orderNo: OrderNo,
                  matNo: MatNo
              },
            func);
    };

}

this.AysPost = function (_methodName, _postData, func, async) {
    //waitingDialog({ title: "Loading...", message: "Please wait." });
    var domain = "/service/api.ashx";
    var Async = false;
    if (async == false) {
        Async = false;
    }
    var _data = { metdhodName: _methodName, postData: _postData };
    var uriPost = domain;
    jQuery.ajax({
        type: "POST",
        url: uriPost,
        async: Async,
        data: _data,
        dataType: "json",
        success: function (data) {
            if (func) {
                if (data && data.Error === '-0') {
                    window.location = '/Page/login.aspx';
                }
                func(data);
            }
            //if (_methodName != 'GetCurrentUserDetail') {
            //closeWaitingDialog();
            //}
        },
        error: function (data) {
            if (func) {
                func(data);
            }
        }
    });
};

function formatDate(val) {
    if (val === null || val === '') {
        return null;
    }
    else {
        var d = new Date(parseInt(val.substr(6)));
        return jQuery.datepicker.formatDate('dd-MM-yy', d) + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
    }
}

function updateStatusBar(val) {
    if (val === null || val === '') {
        return null;
    }
    else {
        jQuery("#errorMessage").text(val);
        //return jQuery.datepicker.formatDate('dd-MM-yy', d) + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
    }
}
